'''
Created on 2013-1-11

@author: hanchen
'''
# encoding: utf-8

def ip_dot_to_str(a, b, c, d):
    return "%s.%s.%s.%s" % (a, b, c, d)

def ip_int_arr_to_str(dots):
    return ip_dot_to_str(dots[0], dots[1], dots[2], dots[3])

def ip_str_to_int_arr(ip):
    dots = ip.split(".");
    return [int(dots[0]), int(dots[1]), 
            int(dots[2]), int(dots[3])]

def ip_int_arr_to_int(dots):
    return ((dots[0] << 24) + (dots[1] << 16) 
            + (dots[2] << 8) + dots[3])
    
def ip_str_to_int(ip):
    return ip_int_arr_to_int(ip_str_to_int_arr(ip));
    
def ip_int_to_str(ip):
    return ip_dot_to_str((ip >> 24) & 0xFF, (ip >> 16) & 0xFF, 
                         (ip >> 8) & 0xFF, ip & 0xFF)
    
def main():
    print ip_str_to_int_arr("1.2.3.4")
    print ip_str_to_int("1.2.3.4")
    print ip_int_to_str(ip_int_arr_to_int(ip_str_to_int_arr("1.2.3.4")))

if __name__ == '__main__':
    main()
    